﻿// JavaScript Document
var oldUserTypeID = -1;
var typeIDString = "";

//判断是否为中文
function isChinese( str )
{
	var lst = /[^\u4E00-\u9FA5]/; 
	return !lst.test(str);      
}
//返回字符串的长度
function GetStringLength( str )
{
	var strLength=0;
	for ( i = 0; i < str.length; i ++ )
	{
		if ( isChinese( str.charAt( i ) ) == true )
		{
			strLength = strLength + 2;
		}
		else
		{
			strLength = strLength + 1;
		}
	}
	return strLength;
}
//去掉字符串空格
String.prototype.Trim = function() 
{ 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

//检查真实姓名是否符合规定
function CheckRealName()
{
	var newRealName = document.getElementById("txtRealname").value;
	if ( document.getElementById("txtRealname").value.Trim() == "" )
	{
			document.getElementById("realNameErr").innerHTML = "<span class=\"error\">姓名不能为空！</span>";
			return false;
	}
	else
	{
		var filter1= /[^\u4E00-\u9FA5]/; 
		if( !filter1.test(document.getElementById("txtRealname").value) )
		{ 
			if ( document.getElementById("txtRealname").value.length > 4 || document.getElementById("txtRealname").value.length < 2 )
			{
				document.getElementById("realNameErr").innerHTML = "<span class=\"error\">中文名字的长度为2-4个字!</span>";
				return false; 
			}
		}
		else
		{
			if ( GetStringLength( document.getElementById("txtRealname").value ) > 20 || GetStringLength( document.getElementById("txtRealname").value ) < 4 )
			{
				document.getElementById("realNameErr").innerHTML = "<span class=\"error\">名字的长度为4-20个字符!</span>";
				return false; 
			}
		}
	}
	document.getElementById("realNameErr").innerHTML = " 正确！";
	return true;
}

//检查邮箱是否符合规定
function CheckIdcard()
{
	var newIdcard = document.getElementById("txtIdcard").value;
	if ( newIdcard.Trim() == "" )
	{
		document.getElementById("idcardErr").innerHTML = "<span class=\"error\">身份证号不能为空！</span>";
		return false;
	}
	
	var filter=/^(\d{15}|\d{17}(\d|X|x))$/;
	if(!filter.test(newIdcard))
	{ 
		document.getElementById("idcardErr").innerHTML = "<span class=\"error\">请填写正确身份证号!</span>";
		return false; 
	}
	var sMsg=fristpay.CheckIdCard(newIdcard,document.getElementById("hidUserID").value);
	if(null != sMsg.error)
	{
		document.getElementById("idcardErr").innerHTML = "<span class=\"error\">身份证号检查出错，请刷新页面再试！</span>";
		return false;
	}
	if(sMsg.value=="-1")
	{
		document.getElementById("idcardErr").innerHTML = "<span class=\"error\">身份证号已经有人使用，请重新输入！</span>";
							
		return false;	    
	}	
	document.getElementById("idcardErr").innerHTML = "<span class=\"error\">输入的身份证号可以正常使用！</span>";
			
	return true;
	
}
//检查支付账号是否符合规定
function CheckAccount()
{
	var newAccount = document.getElementById("txtAccount").value;
	if ( newAccount.Trim() == "" )
	{
		document.getElementById("accountErr").innerHTML = "<span class=\"error\">支付账号不能为空！</span>";
		return false;
	}
	return true;
}


//判断空间名称是否为空
function CheckSpaceName(bool)
{
	if ( document.getElementById("txtSpaceName").value.Trim() == "" )
	{
		document.getElementById("spaceNameErr").innerHTML = "<span class=\"error\">空间名称不能为空！</span>";
		return false;
	}
	if (bool)
	{
		document.getElementById("spaceNameErr").innerHTML = "输入的空间名称正确！";
		return true;
	}
	else
	{
		return true; 
	}
}
function checkInput()
{
	//判断昵称
	if ( !CheckRealName() )
	{
		document.getElementById("txtRealname").focus();
		document.getElementById("txtRealname").select();
		return false;
	}
	//检查邮箱是否符合规定
	else if ( !CheckIdcard() )
	{
		document.getElementById("txtIdcard").focus();
		document.getElementById("txtIdcard").select();
		return false;
	}else if(!CheckAccount()){
		document.getElementById("txtAccount").focus();
		document.getElementById("txtAccount").select();
		return false;
	}
	/*else if ( !CheckSpaceName(false) )
	{
		document.getElementById("txtSpaceName").focus();
		document.getElementById("txtSpaceName").select();
		return false;
	}*/
	return true;
}
//判断修改资料提交时，是否满足条件
function ModifyInfo()
{
	
	if ( checkInput()==true )
	{
		var realname = document.getElementById("txtRealname").value;
		var idcard = document.getElementById("txtIdcard").value;
		var bankname=document.getElementById("selBankname").value;
		var account= document.getElementById("txtAccount").value;
		var userid=document.getElementById("hidUserID").value;
		var iRet=fristpay.GetMoney();
		if(null!=iRet.error){
			alert(iRet.error);
		}else{
			if(iRet.value==0)
			{
				Pui.manage.MsgDiv(1,"您还没达到最低支付标准","您还没达到最低支付标准，加油哦！");
				return;
			}
			if(iRet.value==-1)
			{
				Pui.manage.MsgDiv(1,"该账号不存在","该账号不存在");
				return;
			}
			if(iRet.value==-2)
			{
				Pui.manage.MsgDiv(1,"检查是否达到支付标准出错","检查是否达到支付标准出错，请原谅！");
				return;
			}
		}
		var res = fristpay.ModifyPayInfo( userid, realname, idcard, bankname,account );
		if ( null != res.error )
		{
			alert ( res.error ) ;
		}
		else
		{
			if ( res.value == -1 )
			{
				document.getElementById("realnameErr").innerHTML = "<span class=\"error\">会员不存在！</span>";
				return;
			}
			else if ( res.value == -2 )
			{
				document.getElementById("realnameErr").innerHTML = "<span class=\"error\">输入的身份证号已经有用户使用，请重新输入！</span>";
				return;
			}
			else if(res.value==-3)
			{
				Pui.manage.MsgDiv(1,"您还没达到最低支付标准","您还没达到最低支付标准，加油哦！");
				return;
			}
			else if ( res.value == -4 )
			{
				Pui.manage.MsgDiv(1,"确认支付失败！","确认支付失败，请稍后再试！");
				return;
			}
			else
			{
				Pui.manage.MsgDiv(1,"确认支付成功！","确认支付成功！");
			}	
		}
	}
}



